package com.gamecauca.android;



import com.gamecauca.common.CustomAlertDialog;
import com.gamecauca.common.CustomProgressDialog;
import com.gamecauca.facebook.ApiShareLink;


import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

public class FacebookActivity extends Activity{

	private CustomProgressDialog progressDialog;
	private Context mContext;
	private Resources resources;
	
	@Override
	public void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.facebook_share);
		
		mContext = getApplicationContext();
        resources = mContext.getResources();
		
		progressDialog = new CustomProgressDialog(this);	
		progressDialog.showProgressDialog();
		
		String LINK_LIKE_URL_FACBOOK = "http://www.facebook.com/Scoreloop";
        ApiShareLink apiShareLink = new ApiShareLink(this, facebookHandler);
        apiShareLink.setUrl(LINK_LIKE_URL_FACBOOK);
        apiShareLink.setComment("TEST GAME ON FACEBOOK...");
        apiShareLink.share(progressDialog);	
	}
	
	private Handler facebookHandler = new Handler() {
    	@Override
		public void handleMessage(Message msg) {
    		// Code to process the response and update UI.
    		
			Bundle bundle = msg.getData();
			boolean fbStatus = false;
			if(bundle.containsKey("fbStatus")){
				fbStatus = bundle.getBoolean("fbStatus");
			}
			
			if(fbStatus){
				
				Toast.makeText(mContext, resources.getString(R.string.msg_success_share_fb), 5000).show();
				
			}else{
				
				CustomAlertDialog customDialog = new CustomAlertDialog(FacebookActivity.this);
					
				customDialog.setDialogButtonOk(resources.getString(R.string.alert_dialog_button_ok));
				customDialog.setDialogMessage(resources.getString(R.string.msg_network_error));
				customDialog.showAlertDialog(false);
			}
			
			progressDialog.callBack().cancel();
    	}
    };
}
